package com.sgu6.sgu6_machine.adapter;

import android.content.Context;
import android.graphics.Color;
import android.graphics.Typeface;
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.sgu6.sgu6_machine.App;
import com.sgu6.sgu6_machine.R;
import com.sgu6.sgu6_machine.params.RechargeParam;

import java.util.List;

public class MemberRechargeAdapter extends BaseAdapter {

    private Context context;
    private List<RechargeParam> list;

    public MemberRechargeAdapter(Context context, List<RechargeParam> list) {
        this.context = context;
        this.list = list;
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        Holder holder;
        if (convertView == null) {
            convertView = LayoutInflater.from(context).inflate(R.layout.item_member_recharge, null, false);
            holder = new Holder();
            holder.tvRechargeValue = convertView.findViewById(R.id.tvRechargeValue);
            holder.llContainer = convertView.findViewById(R.id.llContainer);
            holder.tvUnit = convertView.findViewById(R.id.tvUnit);
            convertView.setTag(holder);
        } else {
            holder = (Holder) convertView.getTag();
        }
        holder.tvRechargeValue.setText("充"+String.valueOf(list.get(position).rechargeValue)+"赠"+String.valueOf(list.get(position).giftValue));

        if (list.get(position).selected){
            holder.llContainer.setBackgroundResource(R.drawable.shape_recharge_selected);
            holder.tvRechargeValue.setTextColor(Color.WHITE);
            holder.tvUnit.setTextColor(Color.WHITE);

        }else{
            holder.llContainer.setBackgroundResource(R.drawable.shape_recharge_unselected);
            holder.tvRechargeValue.setTextColor(Color.BLACK);
            holder.tvUnit.setTextColor(Color.BLACK);
        }
        return convertView;
    }


    static class Holder {
        TextView tvRechargeValue, tvGiftValue,tvUnit;
        LinearLayout llContainer;
    }
}